package array.nowcoder.easy;

/**
 * @author Stark
 * @description 找出数组中一半以上的数
 * 题目链接：https://www.nowcoder.com/practice/e8a1b01a2df14cb2b228b30ee6a92163?tpId=13&tqId=11181&tPa
 * ge=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
 * @date 2022/4/20 21:15
 **/
public class HalfNumber {
    public int halfNumber(int[] array){
        int num = array[0];
        int count = 0;
        for(int x : array){
            if(count == 0)
                num = x;
            if(x != num)
                count--;
            else
                count++;
        }
        return num;
    }
}
